#include <bits/stdc++.h>
// 2025/02/06
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int n, W, mv, ma, v[101], p[101], dp[30301];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> W;
    mv = INT_MAX, ma = INT_MIN;
    for (int i = 1; i <= n; i++)
        cin >> v[i] >> p[i], mv = min(mv, v[i]), ma = max(ma, v[i]);
    if (mv <= 300){
        for (int i = 1; i <= n; i++)
            for (int j = min(W, (mv + 3) * n); j >= v[i]; j--)
                dp[j] = max(dp[j], dp[j - v[i]] + p[i]);
        cout << dp[W] << endl;
    }
    else{
        for (int i = 1; i <= n; i++)
            for (int j = W / ma; j >= 1; j--)
                dp[j] = max(dp[j], dp[j - 1] + p[i]);
        cout << dp[W / ma] << endl;
    }

    return 0;
}